package com.manage.competition.service.impl;

import com.manage.competition.entity.DoubleLevelOption;
import com.manage.competition.mapper.DoubleLevelOptionMapper;
import com.manage.competition.repository.DoubleLevelOptionRepository;
import com.manage.competition.service.IDoubleOptionService;
import com.manage.competition.util.CurrentUserUtil;
import com.manage.competition.util.SnowflakeUtil;
import com.manage.competition.vo.DoubleLevelOptionVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 23:55 2019/3/29
 * @Description:
 */
@Service
public class DoubleOptionServiceImpl implements IDoubleOptionService {
    @Autowired
    private DoubleLevelOptionMapper doubleLevelOptionMapper;

    @Autowired
    private DoubleLevelOptionRepository doubleLevelOptionRepository;

    @Override
    public int insert(DoubleLevelOption doubleLevelOption){
        doubleLevelOption.setId(SnowflakeUtil.nextId());
        doubleLevelOption.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        doubleLevelOption.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return doubleLevelOptionMapper.insert(doubleLevelOption);
    }

    @Override
    public List<DoubleLevelOptionVo> findBySignupInfo(long id) {
        List<DoubleLevelOption> list = doubleLevelOptionRepository.findAllBySignupInformationId(id);
        List<DoubleLevelOptionVo> res = new ArrayList<>();
        for (DoubleLevelOption item:
                list) {
            DoubleLevelOptionVo vo = new DoubleLevelOptionVo();
            BeanUtils.copyProperties(item,vo);
            res.add(vo);
        }
        return res;
    }

    @Override
    public int deleteOption(long id) {
        return doubleLevelOptionMapper.deleteByPrimaryKey(id);
    }
}
